| Conditions | 6 |
| Total Lines | 52 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /*! |
||
| 96 | showTooltip (event) |
||
| 97 | { |
||
| 98 | if (this.tooltipTimeout) |
||
| 99 | { |
||
| 100 | clearTimeout(this.tooltipTimeout); |
||
| 101 | } |
||
| 102 | |||
| 103 | // Represents the timeout for showing a tooltip. |
||
| 104 | this.tooltipTimeout = setTimeout(function() { |
||
| 105 | let title = event.target.getAttribute('data-title'); |
||
| 106 | if (title) |
||
| 107 | { |
||
| 108 | // <div id="site_tooltip"><div id="site_tooltipText"><span class="tooltip" |
||
| 109 | let tooltip = document.createElement('div'); |
||
| 110 | tooltip.id = this.settings.tooltipID; |
||
| 111 | |||
| 112 | let tooltipText = document.createElement('div'); |
||
| 113 | tooltipText.id = this.settings.tooltipTextID; |
||
| 114 | |||
| 115 | let span = document.createElement('span'); |
||
| 116 | span.className = this.settings.tooltipClass; |
||
| 117 | |||
| 118 | // Create our element and append it to the body. |
||
| 119 | tooltip.appendChild(tooltipText); |
||
| 120 | tooltip.appendChild(span); |
||
| 121 | document.getElementsByTagName('body')[0].appendChild(tooltip); |
||
| 122 | |||
| 123 | // Load the tooltip content with our data-title |
||
| 124 | if (this.settings.tooltipContent === 'html') |
||
| 125 | { |
||
| 126 | // Regular expression to match content inside .bbc_code_inline span |
||
| 127 | let regex = new RegExp('(<span class="bbc_code_inline">).*?(<\/span>)', 's'); |
||
| 128 | |||
| 129 | title = title.replace(regex, function(match, p1, p2) |
||
| 130 | { |
||
| 131 | let content = match.slice(p1.length, -p2.length); |
||
| 132 | let replacedContent = content.replace(/</g, "<"); |
||
| 133 | return p1 + replacedContent + p2; |
||
| 134 | }); |
||
| 135 | |||
| 136 | tooltipText.innerHTML = title; |
||
| 137 | } |
||
| 138 | else |
||
| 139 | { |
||
| 140 | tooltipText.innerText = title; |
||
| 141 | } |
||
| 142 | |||
| 143 | tooltip.style.display = 'block'; |
||
| 144 | this.positionTooltip(event); |
||
| 145 | } |
||
| 146 | }.bind(this), 1000); |
||
| 147 | } |
||
| 148 | |||
| 170 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.